package com.sykj.cloud.system.controller;

import com.sykj.cloud.common.core.utils.poi.ExcelUtil;
import com.sykj.cloud.common.core.web.controller.BaseController;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.common.core.web.page.TableDataInfo;
import com.sykj.cloud.common.log.annotation.Log;
import com.sykj.cloud.common.log.enums.LogUserType;
import com.sykj.cloud.common.security.annotation.PreAuthorize;
import com.sykj.cloud.system.domain.SysObjectDefine;
import com.sykj.cloud.system.service.ISysObjectDefineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 对象定义 Controller
 *
 * @author mr.will
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/object_define")
public class SysObjectDefineController extends BaseController
{
    @Autowired
    private ISysObjectDefineService sysObjectDefineService;

    /**
     * 新增对象定义
     */
    @PreAuthorize(hasPermi = "system:object_define:add")
    @Log(title = "对象定义 ", logUserType = LogUserType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysObjectDefine sysObjectDefine)
    {
        return toAjax(sysObjectDefineService.insertSysObjectDefine(sysObjectDefine));
    }

    /**
     * 修改对象定义
     */
    @PreAuthorize(hasPermi = "system:object_define:edit")
    @Log(title = "对象定义 ", logUserType = LogUserType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysObjectDefine sysObjectDefine)
    {
        return toAjax(sysObjectDefineService.updateSysObjectDefine(sysObjectDefine));
    }

    /**
     * 删除对象定义
     */
    @PreAuthorize(hasPermi = "system:object_define:remove")
    @Log(title = "对象定义 ", logUserType = LogUserType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(sysObjectDefineService.deleteSysObjectDefineByIds(guids));
    }

    /**
     * 获取对象定义 详细信息
     */
    @PreAuthorize(hasPermi = "system:object_define:query")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(sysObjectDefineService.getSysObjectDefineById(guid));
    }

    /**
     * 导出对象定义 列表
     */
    @PreAuthorize(hasPermi = "system:object_define:export")
    @Log(title = "对象定义 ", logUserType = LogUserType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysObjectDefine sysObjectDefine) throws IOException
    {
        List<SysObjectDefine> list = sysObjectDefineService.listSysObjectDefines(sysObjectDefine);
        ExcelUtil<SysObjectDefine> util = new ExcelUtil<SysObjectDefine>(SysObjectDefine.class);
        util.exportExcel(response, list, "object_define");
    }

    /**
     * 查询对象定义 列表
     */
    @PreAuthorize(hasPermi = "system:object_define:list")
    @GetMapping("/list")
    public TableDataInfo list(SysObjectDefine sysObjectDefine)
    {
        startPage();
        List<SysObjectDefine> list = sysObjectDefineService.listSysObjectDefines(sysObjectDefine);
        return getDataTable(list);
    }
}
